package common.library.utils;

import android.animation.Animator;
import android.app.Activity;
import android.widget.ImageView;

public class AnimationUtil {

    public static void playScan(final ImageView imageView) {
        final boolean[] up = {false};
        imageView.animate().y(200).setDuration(0).setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (up[0])
                    imageView.animate().y(200).setDuration(1000);
                else
                    imageView.animate().y(490).setDuration(1000);
                up[0] = !up[0];
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    }

    public static void playScan(Activity activity, int imageId) {
        ImageView imageView = activity.findViewById(imageId);
        playScan(imageView);
    }
}
